package com.riwon.im.common.utils;

import okhttp3.OkHttpClient;
import okhttp3.Request;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * @author wpy
 * @date 2018/5/9 18:07
 */
public class HttpClientUtils {
    static private OkHttpClient httpClient;

    static {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.readTimeout(5, TimeUnit.SECONDS);
        builder.writeTimeout(5, TimeUnit.SECONDS);
        httpClient = builder.build();
    }

    public static String get(String url) throws IOException {
        Request.Builder builder = new Request.Builder();
        builder.header("Content-Type", "text/html; charset=utf-8");
        Request request = builder.url(url).build();
        return httpClient.newCall(request).execute().body().string();
    }

}
